import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;


public class ToHexa {
	
	public static void toHexa(String readFrom, String writeTo) throws FileNotFoundException, IOException{

		   BufferedReader in=new BufferedReader(new FileReader(readFrom));
	        BufferedWriter out = new BufferedWriter(new FileWriter(writeTo));

	        
	        String input="";
	        int br=0,i=0;
	        char[] buff = new char[4];

	        while (in.read(buff)!=-1){
	        	i++;
	        	System.out.println(i);
		       input+=buff[0];
		       input+=buff[1];
		       input+=buff[2];
		       input+=buff[3];
		       
		       br++;
	           int broj= Integer.parseInt(input,2);
	           String hexString = Integer.toHexString(broj);
	           input="";
	           //System.out.println(i);
	           if(br == 80){
	        	   out.write(hexString+"\n");
	        	   
	        	   br=0;
	           }
	           else{
	        	   out.write(hexString);
	           }
	           
	        }
	         in.close();
	         out.close();
     }
	
	/*
	public String binToHex(String input, String writeTo) throws IOException{
		
		BufferedWriter out = new BufferedWriter(new FileWriter(writeTo));
		String hexa="";

		while(input.length()%8!=0){
            input+="0";
       }
       int br=0;

       for(int i=0;i<input.length();){
       	br++;
          int broj= Integer.parseInt(input.substring(i,i+4),2);
          String hexString = Integer.toHexString(broj);
          if(br == 80){
       	   out.write(hexString+"\n");
       	   br=0;
          }
          else{
       	   out.write(hexString);
          }
          i+=4;

      }
        out.close();
		return hexa;
	}
*/	
	public static void main(String args[]) throws IOException{
	
		/*String fileName="polinomi//polinomi1.txt";
	    
		
		//za generiranje na polinomi
		LFSR l=new LFSR();
		LinkedList<Polinom> polinomList= new LinkedList<Polinom>();		
		polinomList=l.getPolinom(fileName);
		*/
		
		//konvertiraj ja binarnata datotekata vo hehsa
		for(int i=0; i<1 /*polinomList.size()*/; i++){
		
			toHexa("datoteki//q1.txt", "diehard//h1.txt");
			//toHexa("datoteki//q"+ polinomList.get(i).getQuasigroup() + ".txt", "diehard//h"+ polinomList.get(i).getQuasigroup() + ".txt");
			
		}
	}
			
}
